home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / lib / mntlib44.zoo / mntlib / rewinddi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-01  |  914 b   |  51 lines

  1. /* rewinddir routine */
  2.  
  3. /* under MiNT (v0.9 or better) these use the appropriate system calls.
  4.  * under TOS or older versions of MiNT, they use Fsfirst/Fsnext
  5.  *
  6.  * Written by Eric R. Smith and placed in the public domain
  7.  */
  8.  
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <types.h>
  12. #include <limits.h>
  13. #include <dirent.h>
  14. #include <errno.h>
  15. #include <osbind.h>
  16. #include <mintbind.h>
  17. #include "lib.h"
  18.  
  19. extern int __mint;
  20. extern ino_t __inode;    /* in stat.c */
  21.  
  22. void
  23. rewinddir(dirp)
  24.     DIR *dirp;
  25. {
  26.     long r;
  27.     _DTA *olddta;
  28.  
  29.     if (__mint >= 9) {
  30.         (void)Drewinddir(dirp->handle);
  31.         dirp->buf.d_off = 0;
  32.         return;
  33.     }
  34.  
  35. /* I wish POSIX had allowed an error to occur here! */
  36.     if (!dirp->dirname) {
  37.         return;
  38.     }
  39.  
  40.     olddta = Fgetdta();
  41.     Fsetdta(&(dirp->dta));
  42.     r = Fsfirst(dirp->dirname, 0x17);
  43.     Fsetdta(olddta);
  44.     if (r == 0) {
  45.         dirp->status = _STARTSEARCH;
  46.     } else {
  47.         dirp->status = _NMFILE;
  48.     }
  49.     dirp->buf.d_off = 0;
  50. }
  51.